import { defaultListRequestParams } from '@/config';
import api from '@/services/goods/inventory-management';

export type InventoryManagementList = InventoryManagementApi.ListResponse;
export const getFilterList = async () => {
  const res = await api.getFilterList();
  return res.data;
};
export const getList = async (params: InventoryManagementApi.ListParams) => {
  const res = await api.getList<InventoryManagementList>(params);
  const tableData: Requestor.TableFormatedData<InventoryManagementList> = {
    data: res.listData,
    current: res.page + 1,
    pageSize: res.limit,
    total: res.count,
    success: res.success,
  };

  return tableData;
};
export const getAllList = async () => {
  const requestParams: InventoryManagementApi.ListParams = {
    ...defaultListRequestParams,
    page: 0,
    limit: 500,
  };
  const res = await api.getList<InventoryManagementList>(requestParams);
  return res.listData;
};
export const updateWarehouse = async (params: InventoryManagementApi.WarehouseParams) => {
  const data = await api.updateWarehouse(params);
  return data;
};
export const updateShipment = async (params: InventoryManagementApi.ShipmentParams) => {
  const data = await api.updateShipment(params);
  return data;
};

export default {
  getFilterList,
  getList,
  getAllList,
  updateWarehouse,
  updateShipment,
};
